<template>
	<view>
		<mumu-get-qrcode @success='qrcodeSucess' @error="qrcodeError"></mumu-get-qrcode>
	</view>
</template>

<script>
	// js
	import mumuGetQrcode from '@/uni_modules/mumu-getQrcode/components/mumu-getQrcode/mumu-getQrcode.vue'
	// 嫌路径长的话可以单独复制出来
	export default {
		components: {
			mumuGetQrcode
		},
		methods: {
			qrcodeSucess(data) {
				// 创建一个URL对象
				const urlObject = new URL(data);
				// 获取查询参数对象
				const params = new URLSearchParams(urlObject.search);
				// 获取sn参数的值
				const snValue = params.get('sn');
				uni.showModal({
					title: '成功',
					content: snValue,
					success: (res) => {
						if (res.confirm) {
							uni.setStorageSync("device_name", snValue)
						}
						uni.navigateBack({})
					}
				})
			},
			qrcodeError(err) {
				console.log(err)
				uni.showModal({
					title: '摄像头授权失败',
					content: '摄像头授权失败，请检测当前浏览器是否有摄像头权限。',
					success: () => {
						uni.navigateBack({})
					}
				})
			}
		}
	}
</script>

<style lang='scss' scoped>

</style>